<template>
	<vk-data-dialog
		v-model="value.show"
		:title="page.title"
		:top="page.top"
		:width="page.width"
		:close-on-click-modal="true"
		mode="form"
		@open="onOpen"
		@closed="onClose"
	>
		<!-- 页面主体内容开始 -->
		<vk-data-form
			ref="form1"
			v-model="form1.data"
			:form-type="value.mode"
			:rules="form1.props.rules"
			:action="form1.props.action"
			:columns="form1.props.columns"
			:loading.sync="form1.props.loading"
			:labelWidth="form1.props.labelWidth"
			:show-cancel="page.showCancel"
			:cancel-text="page.cancelText"
			:submit-text="page.submitText"
			@success="onFormSuccess"
		></vk-data-form>
		<!-- 页面主体内容结束 -->
	</vk-data-dialog>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk; // vk实例
export default {
	props: {
		value: {
			Type: Object,
			default: function() {
				return {
					show: false,
					mode: "",
					item: {}
				};
			}
		}
	},
	data: function() {
		// 组件创建时,进行数据初始化
		return {
			page: {
				title: "修改收货信息",
				submitText: "确定",
				cancelText: "关闭",
				showCancel: true,
				top: "7vh",
				width: "500px"
			},
			form1: {
				// 表单请求数据，此处可以设置默认值
				data: {
					// _id:'',
					// 对应的详细地址
					address:'',
					// 收货人姓名
					receiver_name:'',
					// 收货人手机号
					receiver_mobile:'',
					// 选择完对应的地址之后要把对应的数据给填进去
					codes:[]
				},
				// 表单属性
				props: {
					// 表单请求地址
					action: "admin/business/sys/order.updateReceiverInfo",
					// 表单字段显示规则
					columns: [
						{ key:"position", title:"地址", type:"address" },
						{ key:"address", title:"街道地址信息", type:"text"} ,
						{ key:"receiver_name", title:"收货人姓名", type:"text" },
						{ key:"receiver_mobile", title:"收货人手机号", type:"text" },
					],
					// 表单验证规则
					rules: {
						receiver_mobile: [
							{ validator: vk.pubfn.validator("mobile"),  message: '手机号格式错误', trigger: 'blur' }
						],
					},
					// 左侧label的宽度
					labelWidth: "100px",
				}
			}
		};
	},
	mounted() {
		that = this;
		that.init();
	},
	methods: {
		// 初始化
		init() {
			let { value } = that;
			that.$emit("input", value);
		},
		// 监听 - 页面打开
		onOpen() {
			that = this;
			let { item={} } = that.value;
			// 每次打开时，重新设置表单的值 = value.item 的值，item通过 vk.pubfn.openForm('表单名',{ item:{ _id:"1" } }) 传递值
			that.form1.data = {
				_id:item._id,
				position:item.express_info.position,
				address:item.express_info.position.address,
				receiver_name:item.express_info.receiver_name,
				receiver_mobile:item.express_info.receiver_mobile,
			}
		},
		// 监听 - 页面关闭
		onClose() {
			//that.$refs.form1.resetForm(); // 关闭时，重置表单
		},
		// 监听 - 提交成功后
		onFormSuccess(res) {
			that.value.show = false; // 关闭页面
			if(res.data.info){
				that.value.item.express_info = res.data.info.express_info;
			}
			that.$emit("success");
		}
	},
	watch: {
		
	},
	// 计算属性
	computed: {}
};
</script>

<style lang="scss" scoped></style>
